/*
 * openTFile.java
 *
 * Created on August 24, 2007
 *
 * @author Alex Riedler (Ultrahex)
 *
 * @description
 *      Used for reading/open and writing/saving of source code files
 *           
 */

package ca.compsci.opent.ide;

import java.io.*;

public class openTFile {
    File file;

    public openTFile(File file) {
        this.file = file;
    }
    
    public boolean saveFile(String fileText) {
        try {
            PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));
            output.print(fileText);
            output.flush();
            output.close();
        } catch (Exception e) {
            return false;
        }
        return true;
    }
    
    public String toString() {
        StringBuffer buffer;
        String output = "";
        String line;

        try {
          FileReader in = new FileReader (file);
          BufferedReader bin = new BufferedReader (in);
          buffer = new StringBuffer () ;

          while ((line = bin.readLine ()) != null) {
                buffer.append (line + "\n");
          }

          in.close ();
          output = buffer.toString ();
        }
        catch (Exception e) {
          return "";
        }
        
        return output;
    }
    
}
